import urllib.request
import urllib.parse
import string


def get_method_params():
    url = "http://www.baidu.com/s?wd="
    name = '美女'
    final_url = url + name
    encode_name = urllib.parse.quote(final_url, safe=string.printable)
    # print(encode_name) #转义后：http://www.baidu.com/s?wd=%E7%BE%8E%E5%A5%B3

    # get请求
    # 将包含汉字的网址进行转义
    response = urllib.request.urlopen(encode_name)
    print(response.read().decode('utf-8'))


get_method_params()

# UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-11: ordinal not in range(128)
# 原因：python解释性语言  解析器只支持ascii0-127之间  不支持中文
